package torres.ability;

import java.util.List;

import torres.entity.Entity;
import torres.entity.Sneak;
import torres.item.TrapItem;
import torres.map.Location;
import torres.map.World;

/**
 * @author Torres
 * NonActionAbility that removes TrapItems
 */
public class RemoveTrapAbility extends NonActionAbility {

	/**
	 * Creates a new RemoveTrapAbility with given name
	 * @param name Name of RemoveTrapAbility
	 */
	public RemoveTrapAbility(String name, int id, List<Cost> costs) {
		super(name, id, costs);
	}

	/**
	 * Calls RemoveTrapAbility on given Entity
	 * @param e Entity that will use RemoveTrapAbility
	 * @see torres.ability.NonActionAbility#useAbility(torres.entity.Entity)
	 */
	public void useAbility(Entity e) {
		Location trapLocation = Location.locationInDirection(e.getLocation(), e.getDirection());
		TrapItem trap = World.getInstance().getTrap(trapLocation);
		Sneak s = (Sneak)e.getOccupation();
		if(trap != null) {
			trap.attemptToRemove(s.getDetectRemoveTrapSkill());
			if(trap.isConsumed())
				World.getInstance().removeTrap(trapLocation);
		}
	}

}
